<template>
  <el-container>
    <el-header>
      <app-header v-show="headervisible"></app-header>
    </el-header>
    <el-main class="p0">
      <app-main></app-main>
    </el-main>
    <el-footer class="p0">
      <app-footer></app-footer>
    </el-footer>
  </el-container>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted } from "vue";
import appHeader from "@/components/home/header.vue";
import appMain from "@/components/home/main.vue";
import appFooter from "@/components/home/footer.vue";

export default defineComponent({
  name: "Home",
  components: { appHeader, appMain, appFooter },
  setup() {
    const state = reactive({
      headerVisible: false,
    });

    const handleScroll: any = (e: any) => {
      console.log(e.target.scrollingElement.scrollTop);
      if (e.target.scrollingElement.scrollTop > 60) {
        state.headerVisible = true;
        console.log(state.headerVisible);
      } else {
        state.headerVisible = false;
        console.log(state.headerVisible);
      }
    };

    onMounted(() => {
      document.querySelector("body")!.onscroll = handleScroll;
      // document.documentElement.scrollTop; //firefox
      // document.documentElement.scrollLeft; //firefox
      // document.body.scrollTop; //IE
      // document.body.scrollLeft; //IE
    });

    return {
      ...toRefs(state),
      handleScroll,
    };
  },
});
</script>

<style lang="scss" scoped>
</style>
